﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using PasswordManager.Src.DAO;

namespace PasswordManager.Src.UI
{
    public partial class SettingPage : PhoneApplicationPage
    {
        public SettingPage()
        {
            InitializeComponent();
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            PasswordManagerDataContext db = new PasswordManagerDataContext();
            if(db.AppSettinges.First().Language=="en-US")
            {
                radEnglish.IsChecked=true;
            }
            else
            {
                radVietNam.IsChecked = true;
            }
        }

        private void radEnglish_Checked(object sender, RoutedEventArgs e)
        {
            PasswordManagerDataContext db = new PasswordManagerDataContext();
            db.AppSettinges.First().Language = "en-US";
            db.SubmitChanges();
            AppSetting.InitLanguage();
            //NavigationService.Navigate(new Uri("/Src/UI/MainPage.xaml", UriKind.Relative));
        }

        private void radVietNam_Checked(object sender, RoutedEventArgs e)
        {
            PasswordManagerDataContext db = new PasswordManagerDataContext();
            db.AppSettinges.First().Language = "vi-VN" ;
            db.SubmitChanges();
            AppSetting.InitLanguage();
            //NavigationService.Navigate(new Uri("/Src/UI/SettingPage.xaml", UriKind.Relative));
        }

        private void PhoneApplicationPage_BackKeyPress(object sender, System.ComponentModel.CancelEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Src/UI/MainPage.xaml", UriKind.Relative));
        }
    }
}